package io.sxl.modules.generator.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.sxl.modules.generator.entityx.ProIdandName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.sxl.common.utils.PageUtils;
import io.sxl.common.utils.Query;

import io.sxl.modules.generator.dao.ProjectDao;
import io.sxl.modules.generator.entity.ProjectEntity;
import io.sxl.modules.generator.service.ProjectService;


@Service("projectService")
public class ProjectServiceImpl extends ServiceImpl<ProjectDao, ProjectEntity> implements ProjectService {

    @Autowired
    private ProjectDao dao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProjectEntity> page = this.page(
                new Query<ProjectEntity>().getPage(params),
                new QueryWrapper<ProjectEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<ProIdandName> queryIdandName() {
        List<ProjectEntity> projectEntities = dao.selectList(new QueryWrapper<ProjectEntity>().select("id", "name"));
        List<ProIdandName> idandNames = new ArrayList<>();
        projectEntities.forEach(s->{
            idandNames.add(new ProIdandName(s.getId(),s.getName()));
        });
        return idandNames;
    }
}
